package com.xiyoumobile.dengtuo.flowershop;

import android.app.Activity;
import android.media.Image;
import android.os.Bundle;
import android.view.View;

import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.TextView;

import javahtml5.JsKindsActivity;
import javahtml5.JsMainActivity;

public class KindsActivity extends Activity {

    private WebView webView;

    TextView textView;
    ImageButton imageButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kinds);

        findView();
    }

    private void findView() {

        imageButton = (ImageButton) findViewById(R.id.title_bar_back);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                finish();
            }
        });

        textView = (TextView) findViewById(R.id.title);

        //获取传过来的参数
        int id = getIntent().getIntExtra("id", 0);
        String name = getIntent().getStringExtra("name");
        textView.setText(name);

        webView = (WebView) findViewById(R.id.webView);
        // WebView打开权限
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setSupportZoom(true);

        webView.setWebViewClient(new WebViewClient());
        JsKindsActivity javaSrcipt =
                new JsKindsActivity(KindsActivity.this, webView);
        webView.addJavascriptInterface(javaSrcipt, "native");


        initWebView(id);
    }

    private void initWebView(int id) {

        switch (id) {

            case 0: {
                webView.loadUrl("file:///android_asset/kind0.html");
                break;
            }
            case 1: {
                webView.loadUrl("file:///android_asset/kind1.html");
                break;
            }
            case 2: {
                webView.loadUrl("file:///android_asset/kind2.html");
                break;
            }
            case 3: {
                webView.loadUrl("file:///android_asset/kind3.html");
                break;
            }
            case 4: {
                webView.loadUrl("file:///android_asset/kind4.html");
                break;
            }
            case 9: {
                webView.loadUrl("file:///android_asset/kind9.html");
                break;
            }
            case 10: {
                webView.loadUrl("file:///android_asset/kind10.html");
                break;
            }

            case 11: {
                webView.loadUrl("file:///android_asset/eternal.html");
                break;
            }
            default:
                break;


        }

    }
}
